/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utility;

import java.util.ResourceBundle;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.validator.ValidatorException;

/**
 *
 * @author Carmela
 */
public class ExceptionThrower {
    
    /**
     * Questo motodo aggiunte un messaggio nel contesto di tipo errore
     * @param context il FacesContext
     * @param resourceBundle il resource bundle
     * @param resourceMessage il messaggio contenuto nel bundle
     */
    public static void throwMessageError(FacesContext context, ResourceBundle resourceBundle, String resourceMessage){
        FacesMessage message=new FacesMessage();
        message.setSummary(resourceBundle.getString(resourceMessage));
        message.setSeverity(FacesMessage.SEVERITY_ERROR);
        context.addMessage(null, message);
    }
    
     public static void throwMessageError(FacesContext context, ResourceBundle resourceBundle, String resourceMessage, String toAppend){
        FacesMessage message=new FacesMessage();
        message.setSummary(resourceBundle.getString(resourceMessage)+toAppend);
        message.setSeverity(FacesMessage.SEVERITY_ERROR);
        context.addMessage(null, message);
    }
    
    public static void throwMessageInfo(FacesContext context, ResourceBundle resourceBundle, String resourceMessage){
        FacesMessage message=new FacesMessage();
        message.setSummary(resourceBundle.getString(resourceMessage));
        message.setSeverity(FacesMessage.SEVERITY_INFO);
        context.addMessage(null, message);
    }
    
    public static void throwMessageInfo(FacesContext context, ResourceBundle resourceBundle, String resourceMessage, String toAppend){
        FacesMessage message=new FacesMessage();
        message.setSummary(resourceBundle.getString(resourceMessage)+toAppend);
        message.setSeverity(FacesMessage.SEVERITY_INFO);
        context.addMessage(null, message);
    }
    
    public static void throwValidationException(FacesContext context, ResourceBundle resourceBundle, String resourceMessage){
        FacesMessage message=new FacesMessage();
        message.setSummary(resourceBundle.getString(resourceMessage));
        message.setSeverity(FacesMessage.SEVERITY_ERROR);
        throw new ValidatorException(message);
    }
}
